package com.example.h.weixinui3;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.
 */
public class ThreeFragment extends Fragment {

    public ThreeFragment() {
        // Required empty public constructor
    }

    private ListView listView_1;
    private List<Map<String,Object>> data;
    private SimpleAdapter adapter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_three, container, false);
        listView_1=(ListView)view.findViewById(R.id.listView_1);
        //绑定数据
        String[] from={"w1","w2","w3","w4","w5"};
        int[] to={R.id.w1,R.id.w2,R.id.w3,R.id.w4,R.id.w5};
        //获取数据源
        getData();
        adapter=new SimpleAdapter(this.getActivity(),data,R.layout.layout_threelist,from,to);
        listView_1.setAdapter(adapter);
        return view;
    }

    //构建数据源
     private void getData(){
        data=new ArrayList<Map<String,Object>>();
        //每一项的数据
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("w1",R.drawable.afn);
        map.put("w2","张三");
        map.put("w3","可以");
        map.put("w4","3天前");
        map.put("w5",R.drawable.afo);
        data.add(map);

        map=new HashMap<String,Object>();
         map.put("w1",R.drawable.afn);
         map.put("w2","张三");
         map.put("w3","可以");
         map.put("w4","3天前");
         map.put("w5",R.drawable.afo);
         data.add(map);

        map=new HashMap<String,Object>();
         map.put("w1",R.drawable.afn);
         map.put("w2","张三");
         map.put("w3","可以");
         map.put("w4","3天前");
         map.put("w5",R.drawable.afo);
         data.add(map);

        map=new HashMap<String,Object>();
         map.put("w1",R.drawable.afn);
         map.put("w2","张三");
         map.put("w3","可以");
         map.put("w4","3天前");
         map.put("w5",R.drawable.afo);
         data.add(map);
    }



}
